package com.wnhz.work.jy.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewParent;

import java.util.List;

/**
 * @author 作者 zxb:
 * @date 创建时间：2016年7月1日
 * @Description
 */

public class MyViewPagerAdapter extends PagerAdapter {
	private List<View> mListViews;

	public MyViewPagerAdapter(List<View> mListViews) {
		this.mListViews = mListViews;

	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView(mListViews.get(position));
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View view = mListViews.get(position);

		// 如果View已经在之前添加到了一个父组件，则必须先remove，否则会抛出IllegalStateException。
		ViewParent vp = view.getParent();
		if (vp != null) {
			ViewGroup parent = (ViewGroup) vp;
			parent.removeView(view);
		}

		container.addView(view, 0);



		return mListViews.get(position);
	}

	@Override
	public int getCount() {
		return mListViews.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}
}
